#import "SMRBorderFrameSunkenRounded.h"
#import "NSShadow+MCAdditions.h"
#import "NSBezierPath+SMRAdditions.h"


#pragma mark Constants
static const CGFloat SMRBorderFrameSunkenRoundedPadding = 10.0f;
static const CGFloat SMRBorderFrameSunkenRoundedCornerRadius = 4.0f;


#pragma mark -
#pragma mark Class Globals
static NSShadow *SMRBorderFrameSunkenRoundedInnerShadow;
static NSShadow *SMRBorderFrameSunkenRoundedUpperInnerShadow;


#pragma mark -
@interface SMRBorderFrameSunkenRounded (SMRBorderFrameSunkenRoundedPrivateMethods)
-(NSBezierPath *)framePathForFrameRect_:(NSRect)aRect;
@end


#pragma mark -
@implementation SMRBorderFrameSunkenRounded

+(void)initialize {
	NSColor *innerShadowColor = [NSColor colorWithCalibratedWhite:0.0 alpha:0.1];
	SMRBorderFrameSunkenRoundedInnerShadow = [[NSShadow alloc] mcInitWithColor:innerShadowColor offset:NSZeroSize blurRadius:5.0f];
	NSColor *upperShadowColor = [NSColor colorWithCalibratedWhite:0.0 alpha:0.1];
	SMRBorderFrameSunkenRoundedUpperInnerShadow = [[NSShadow alloc] mcInitWithColor:upperShadowColor offset:NSMakeSize(0.0f, -3.0f) blurRadius:3.0f];
}

-(NSRect)imageRectForFrameRect:(NSRect)frameRect {
	return NSInsetRect(frameRect, SMRBorderFrameSunkenRoundedPadding, SMRBorderFrameSunkenRoundedPadding);
}

-(CGFloat)horizontalPadding {
	return SMRBorderFrameSunkenRoundedPadding;
}

-(CGFloat)verticalPadding {
	return SMRBorderFrameSunkenRoundedPadding;
}

-(void)drawFrameUnderImageInRect:(NSRect)aRect {
	NSBezierPath *framePath = [self framePathForFrameRect_:aRect];
	[[NSColor colorWithCalibratedWhite:0.5f alpha:0.03f] setFill];
	[framePath fill];
}

-(void)drawFrameOverImageInRect:(NSRect)aRect {
	NSBezierPath *framePath = [self framePathForFrameRect_:aRect];
	[framePath smrFillWithInnerShadow:SMRBorderFrameSunkenRoundedInnerShadow];
	[framePath smrFillWithInnerShadow:SMRBorderFrameSunkenRoundedUpperInnerShadow];
	[[NSColor colorWithCalibratedWhite:0.6f alpha:0.8f] setStroke];
	[framePath stroke];
}

-(NSBezierPath *)framePathForFrameRect_:(NSRect)aRect {
	NSRect frameRect = NSIntegralRect(aRect);
	frameRect = NSInsetRect(frameRect, 1.5f, 1.5f);
	NSBezierPath *framePath = [NSBezierPath bezierPathWithRoundedRect:frameRect xRadius:SMRBorderFrameSunkenRoundedCornerRadius yRadius:SMRBorderFrameSunkenRoundedCornerRadius];
	return framePath;
}

@end
